package sniper.targets;

import java.util.logging.Logger;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;

public class RafbTarget implements Target {

	public static final String DESC_PARAM_NAME = "desc";

	public static final String LANG_PARAM_NAME = "lang";

	private Logger log = Logger.getLogger(RafbTarget.class.getCanonicalName());

	public static final String RAFB_DOMAIN = "http://rafb.net";
	public static final String POST_URL = "/paste/paste.php";
	public static final String NICK_PARAM_NAME = "nick";
	public static final String TEXT_PARAM_NAME = "text";
	
	public void submit(String snippet) throws Exception {
		// TODO Auto-generated method stub
		
		final HttpClient httpClient = new HttpClient();
		
		final PostMethod postMethod = new PostMethod(RAFB_DOMAIN + POST_URL);
		
		
		
		postMethod.setParameter(LANG_PARAM_NAME, "Plain+Text");
		
		postMethod.setParameter(NICK_PARAM_NAME, "sniper");
		
		postMethod.setParameter(DESC_PARAM_NAME, "spike");
		
		postMethod.setParameter(TEXT_PARAM_NAME, snippet);
		
		postMethod.setParameter("cvt_tabs", "No");
		
		log.info("Submitting to: " + postMethod.getURI());
		
		int statusCode = httpClient.executeMethod(postMethod);
		
		String location = postMethod.getResponseHeader("Location").getValue();
		
		postMethod.releaseConnection();
		
		log.info("Released connection");
		
		
		
		
		
		log.info("Status code: " + statusCode);
		log.info("Location: " + location);

	}

}
